def split_txt(src,train_src,test_src):
    with open(src,"r") as  f:   #从指定文件夹打开TXT文件，原文件的编码格式为UTF-8
     lines = f.readlines()
     print(len(lines))
     for i in range(0,len(lines)):
         print(lines[i])
         m = i+1
         if m <= len(lines) * 4 / 5:
            with open(train_src,'a+') as f:
               f.write(lines[i])
         else:
            with open(test_src,'a+') as f:
                f.write(lines[i])

if __name__=="__main__":
    src = './example_02.txt'
    train = './train.txt'
    test = './tset.txt'
    split_txt(src,train,test)